package com.legendary.awesome.Listeners;

import com.legendary.awesome.RandomNumber;
import com.legendary.awesome.SimpleCalculator;

import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;

/*
 * Egen definert lytter, brukes i SimpleCalculator klassen
 */
public class MyOnclickListener implements OnClickListener{

	private SimpleCalculator sc;
	private int id;
	private int upperlimit = 10;
	
	public MyOnclickListener(SimpleCalculator sc,int id)
	{
		this.sc = sc;
		this.id = id;
	}
	
	@Override
	public void onClick(View v) {
		
		if(sc.getbAnswer().isPressed())
		{
			sc.showDialog(id);
		}
		
		if(sc.getbNrOne().isPressed())
		{
			Intent request = new Intent(sc, RandomNumber.class);
			request.putExtra("GRNumber", "Generate a random number");
			request.putExtra("UpperLimitValue", upperlimit);
			sc.startActivityForResult(request,SimpleCalculator.REQUEST_CODE);
		}
		
		if(sc.getbNrTwo().isPressed())
		{
			Intent request = new Intent(sc, RandomNumber.class);
			request.putExtra("GRNumber", "Generate a random number");
			request.putExtra("UpperLimitValue", upperlimit);
			sc.startActivityForResult(request,SimpleCalculator.REQUEST_CODE2);
		}
	}
}